<?php
class Page extends MY_Controller {
    /**
    * Responsable for auto load the model
    * @return void
    */
   public function __construct(){
		parent::__construct();
   }
	
	function index(){
		$data = array();
		$slug = $this->uri-> segment(1);
		if($slug == 'tin-tuyen-dung'){
			$this->load->model('tuyendung_m', 'tuyendung');
			$data['page_content']	=	'tuyendung/dstuyendung';
			$data['page_title']	=	'Bảng tin tuyển dụng';
			$config['per_page'] = 10;
			$config['base_url'] = base_url('tin-tuyen-dung');
			$config['use_page_numbers'] = TRUE;
			$config['num_links'] = $this->config->item('num_links');
			$config['full_tag_open'] = '<ul class="pagination clear">';
			$config['full_tag_close'] = '</ul>';
			$config['num_tag_open'] = '<li>';
			$config['num_tag_close'] = '</li>';
			$config['cur_tag_open'] = '<li class="active"><a>';
			$config['cur_tag_close'] = '</a></li>';
			$config['next_tag_open']	=	'<li>';
			$config['next_tag_close']	=	'</li>';
			$config['next_link']			=	'&rsaquo;';
			$config['prev_link']			=	'&lsaquo;';
			$config['prev_tag_open']	=	'<li>';
			$config['prev_tag_close']	=	'</li>';
			$config['first_tag_open']	=	'<li>';
			$config['first_link']		=	'&lsaquo;&lsaquo;&nbsp;';
			$config['first_tag_close']	=  '</li>';
			$config['last_tag_open']	=	'<li>';
			$config['last_link']			=	'&nbsp;&rsaquo;&rsaquo;';
			$config['last_tag_close']	=	'</li>';
			$config['uri_segment']		= 	2;
			$config['suffix']				=	'.html';			
			$paged = $this->uri->segment(2);
			$paged = ($paged * $config['per_page']) - $config['per_page'];
			if ($paged < 0) $paged = 0;				
			//for search
			
			$tinh_thanh = $this->input->get('tinh_thanh');
			$lhinh = $this->input->get('lhinh');			
			// print_r($lhinh);die;
			// $dichvu = $this->input->get('dichvu');
			$search_term = array(
				'tinh_thanh'	=>	$tinh_thanh ? $tinh_thanh : 0,
				'lhinh'			=>	$lhinh ? $lhinh : 0,
				// 'dichvu'			=> $dichvu
			);
			$this->session->set_userdata('search_term', $search_term);
			if($paged == 0)
				$this->session->unset_userdata('search_term');
			$tmp = $this->session->userdata('search_term');
			if($tmp)
				$search_term = array_merge($search_term, $tmp);
			$data['sterm']	=	$search_term;
			$data['loai_hinh'][0] = 'Tất cả';
			foreach($this->tuyendung->get_loai_hinh() as $obj)
				$data['loai_hinh'][$obj->id]	= $obj->ten;
			//
			$filter = array_merge(array(
				'limit'		=>	$config['per_page'],
				'paged'		=>	$paged,
			),$search_term);	
			$config['total_rows'] = $this->tuyendung->get_tin_tuyen_dung($filter, true);
			// echo $this->db->last_query();die;
			$data['list']		= $this->tuyendung->get_tin_tuyen_dung($filter);
			// echo $this->db->last_query();die;
			$this->pagination->initialize($config);
			$data['content'] 	= 'tuyendung/dstuyendung';
			$data['quangcao'] = 'tpl/quangcao';
			$this->load->view('tpl/template', $data);
			return;
		}else{
			// echo '<pre>';print_r($this->pages);die;
			$this->load->model('Pages_m','page');
			$page = $this->page->get_page_by_slug($slug);
			if(!$page)
				show_404();
			$data['page_content']	=	$page->content;
			$data['page_title']	=	$page->title;
		}
		// #echo $this->db->last_query();die;
		$data['title'] 	= 'Dịch vụ PG Tiệc - PG Tour';		
		$data['content'] 	= 'page';
		$data['quangcao'] = 'tpl/quangcao';
		$this->load->view('tpl/template', $data);
	}
 }